package com.ljsw.dialog;

import com.ljsw.activity.R;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

/**
 * 双人指纹验证 Dialog
 * 作者: 石锚
 * 版本: 1.0
 * 日期: 2015-10-15
 */
public class FingerDialog {
	
	public FingerDialog(Context context) {
		super();
		this.context = context;
		WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
		display = windowManager.getDefaultDisplay();//获取屏幕分辨率
	}
	
	private Context context;
	private Display display;
	private Dialog dialog;
	private LinearLayout layout_finger;
	private TextView finger_title,finger_name1,finger_name2,finger_tishi;
	private ImageView finger_image1,finger_image2;//指纹图片
	
	public FingerDialog builder(){
		View view = LayoutInflater.from(context).inflate(R.layout.dialog_finger_check, null);
		layout_finger = (LinearLayout) view.findViewById(R.id.layout_finger);
		finger_title = (TextView) view.findViewById(R.id.finger_title);
		finger_name1 =  (TextView) view.findViewById(R.id.finger_name1);
		finger_name2 =  (TextView) view.findViewById(R.id.finger_name2);
		finger_image1 = (ImageView) view.findViewById(R.id.finger_image1);
		finger_image2 = (ImageView) view.findViewById(R.id.finger_image2);
		finger_tishi =  (TextView) view.findViewById(R.id.finger_tishi);
		// 添加Dialog样式
		dialog = new Dialog(context, R.style.FingerDialog);
		dialog.setContentView(view);
	//	dialog.setCanceledOnTouchOutside(false);// 设置点击Dialog外部任意区域不关闭Dialog	
		// 调整dialog背景大小
		
		layout_finger.setLayoutParams(new FrameLayout.LayoutParams((int) (display
				.getWidth() * 0.85), LayoutParams.WRAP_CONTENT));
		return this;
		
	}
	
	/**
	 * 设置标题
	 * @param title
	 * @return
	 */
	public FingerDialog setTitle(String title){	
		finger_title.setText(title);
		return this;
	}
	/**
	 * 设置人名左边
	 * @param title
	 * @return
	 */
	public FingerDialog setNameLeft(String name){	
		finger_name1.setText(name);
		return this;
	}
	/**
	 * 设置人名右边
	 * @param title
	 * @return
	 */
	public FingerDialog setNameRight(String name){	
		finger_name2.setText(name);
		return this;
	}
	
	/**
	 * 设置指纹左边
	 * @param title
	 * @return
	 */
	public FingerDialog setFingerLeft(Bitmap map){	
		finger_image1.setImageBitmap(map);
		return this;
	}
	/**
	 * 设置指纹右边
	 * @param title
	 * @return
	 */
	public FingerDialog setFingerRight(Bitmap map){	
		finger_image2.setImageBitmap(map);
		return this;
	}
	
	/**
	 * 点击事件
	 * @param text
	 * @param listener
	 * @return
	 */
	public FingerDialog setQueDing(final OnClickListener listener) {
		layout_finger.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				listener.onClick(v);
				dialog.dismiss();
			}
		});
		return this;
	}
	public void show() {
		dialog.show();
	}
}
